package com.ruoyi.iot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.iot.domain.IotMeasurementDict;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface IotMeasurementDictMapper extends BaseMapper<IotMeasurementDict> {
    @Select("SELECT remote_id FROM ${tableName} WHERE remote_id = #{remoteId}")
    List<String> selectListByRemoteId(@Param("tableName") String tableName, @Param("remoteId") String remoteId);

    @Select("SELECT device_id FROM ${tableName} WHERE remote_id = #{remoteId}")
    List<String> selectDeviceIdListByRemoteId(@Param("tableName") String tableName, @Param("remoteId") String remoteId);

    @Select("SELECT remote_id FROM ${tableName} WHERE remote_id = #{remoteId} AND device_id = #{deviceId}")
    List<String> selectListByRemoteIdAndDeviceId(@Param("tableName") String tableName,
                                                              @Param("remoteId") String remoteId,
                                                              @Param("deviceId") String deviceId);


    @Select("SELECT 1 FROM ${tableName} WHERE remote_id = #{remoteId} AND device_id = #{deviceId}")
    List<Map<String, Object>> checkExistByRemoteIdAndDeviceId(@Param("tableName") String tableName,
                                                              @Param("remoteId") String remoteId,
                                                              @Param("deviceId") String deviceId);

    @Select("SELECT * FROM iot_measurement_dict WHERE measurement = #{measurement}")
    List<IotMeasurementDict> selectListByMeasurement(@Param("measurement")String measurement);
}
